package m1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {

    public static void main(String[] args) throws IOException, TimeoutException {

        //1.链接服务器
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setPort(5672);
        f.setUsername("admin");
        f.setPassword("admin");
        Channel c = f.newConnection().createChannel();

        //2.在服务器上创建helloworld队列
        // 服务已存在的话，不会重复创建
        /**
         * 队列民、是否是持久队列、是否是排他队列，独占队列、是否自动删除、其他参数属性
         */
        c.queueDeclare("helloworld", false, false, false, null);

        //3.发送消息
        /**
         * ""：空串是默认的交换机
         */
        c.basicPublish("", "helloworld", null, "Hello World~".getBytes());

        //4.断开连接
        c.close();

        System.out.println("已发送消息！");


    }

}
